﻿package mortal.game.view.copy.crossMainCity
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.crossMainCity.mainCityPosition.*;
    import mortal.game.view.copy.crossMainCity.panels.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.interfaces.*;

    public class MainCityModule extends BaseWindow
    {
        private var _tab:GTabarNew;
        private var _tabData:Array;
        private var _curPanel:GSprite;
        public static const Index_ViewCareer:int = 0;
        public static const Index_GrantCareer:int = 1;
        public static const Index_KOPanel:int = 2;
        public static const Index_FinalPanel:int = 3;

        public function MainCityModule(param1:ILayer = null)
        {
            this._tabData = [];
            super(param1);
            setSize(889, 605);
            this.title = Language.getString(20973);
            this.layer = LayerManager.windowLayer3D;
            return;
        }// end function

        public function updateRevenueInfo(param1:SMainCityRevenueMsg) : void
        {
            if (this._curPanel == null || !(this._curPanel is MainCityFinalPanel))
            {
                return;
            }
            (this._curPanel as MainCityFinalPanel).updateRevenueInfo(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tab = UIFactory.gTabBarNew(0, 32, this._tabData, 889, 605, 95, 26, this, this.onTabBarChange, "TabButtonNew");
            this.updateTab();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tab.dispose(param1);
            this._tab = null;
            if (this._curPanel)
            {
                this._curPanel.dispose(param1);
                this._curPanel = null;
            }
            this._tabData.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onTabBarChange(event:MuiEvent = null) : void
        {
            if (this._curPanel)
            {
                this._curPanel.dispose();
                this._curPanel = null;
            }
            var _loc_2:* = this._tab.dataProvider[this._tab.selectedIndex];
            var _loc_3:* = _loc_2.name;
            switch(_loc_3)
            {
                case Index_ViewCareer:
                {
                    this.addPostionPanel();
                    break;
                }
                case Index_GrantCareer:
                {
                    this.addPostAppointPanel();
                    break;
                }
                case Index_KOPanel:
                {
                    this.showKOPanel();
                    break;
                }
                case Index_FinalPanel:
                {
                    this.showFinalPanel();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function updateTab() : void
        {
            this._tabData = [];
            this._tabData.push({name:0, label:Language.getString(21420)});
            this._tabData.push({name:1, label:Language.getString(21421)});
            this._tabData.push({name:2, label:Language.getString(20974)});
            this._tabData.push({name:3, label:Language.getString(20975)});
            this._tab.dataProvider = this._tabData;
            return;
        }// end function

        public function changeToTabIndexByName(param1:int) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Object = null;
            _loc_2 = 0;
            while (_loc_2 < this._tab.dataProvider.length)
            {
                
                _loc_3 = this._tab.dataProvider[_loc_2];
                if (_loc_3.name == param1)
                {
                    break;
                }
                _loc_2++;
            }
            if (_loc_2 > this._tab.dataProvider.length)
            {
                _loc_2 = 0;
            }
            this._tab.selectedIndex = _loc_2;
            this.onTabBarChange();
            return;
        }// end function

        private function addPostionPanel() : void
        {
            this._curPanel = UICompomentPool.getUICompoment(MainCityPostionPanel, this);
            this._curPanel.x = 6;
            this._curPanel.y = 64;
            this.addChild(this._curPanel);
            return;
        }// end function

        private function addPostAppointPanel() : void
        {
            this._curPanel = UICompomentPool.getUICompoment(MainCityPostAppointPanel, this);
            this._curPanel.x = 6;
            this._curPanel.y = 64;
            this.addChild(this._curPanel);
            return;
        }// end function

        private function showKOPanel() : void
        {
            this._curPanel = UICompomentPool.getUICompoment(MainCityKOPanel) as MainCityKOPanel;
            this._curPanel.x = 6;
            this._curPanel.y = 64;
            this.addChild(this._curPanel);
            return;
        }// end function

        private function showFinalPanel() : void
        {
            this._curPanel = UICompomentPool.getUICompoment(MainCityFinalPanel, this) as MainCityFinalPanel;
            this._curPanel.x = 6;
            this._curPanel.y = 64;
            this.addChild(this._curPanel);
            return;
        }// end function

    }
}
